package com.lyz.myself.service.ServiceImpl;

import com.lyz.myself.config.utils.JwtUtil;
import com.lyz.myself.config.utils.util.DateUtil;
import com.lyz.myself.controller.BaseController;
import com.lyz.myself.mapper.CustomerFocusMapper;
import com.lyz.myself.pojo.Po.CustomerFocus;
import com.lyz.myself.service.CustomerFocusService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;

/**
 * @program: myself
 * @Date: 2019/1/17 11:29
 * @Author: Mr.Deng
 * @Description:
 */
@Service
public class CustomerFocusServiceImpl extends BaseController implements CustomerFocusService {
    @Autowired
    private CustomerFocusMapper customerFocusMapper;

    /**
     * 关注客户
     *
     * @param customer_id
     * @return
     */
    @Transactional
    @Override
    public boolean insertFocus(String customer_id) {
        List<CustomerFocus> list = new ArrayList<>();
        String[] str = customer_id.split(",");
        for (int i = 0; i < str.length; i++) {
            CustomerFocus customerFocus = new CustomerFocus();
            customerFocus.setCustomer_id(Integer.parseInt(str[i]));
            customerFocus.setUser_id(JwtUtil.getUserId());
            customerFocus.setCompany_id(getUser().getCompany_id());
            customerFocus.setFocus_time(DateUtil.timeMillis());
            list.add(customerFocus);
        }
        boolean boo;
        int focusCustomer = customerFocusMapper.insertFocus(list);
        if (focusCustomer > 0) {
            boo = true;
        } else {
            boo = false;
        }
        return boo;
    }
}
